﻿using System.Collections;
using System.Collections.Generic;
using System.Threading;
using Unity.VisualScripting;

namespace Core.Utils {
    public class ObjectPool<T> where T : class,new() {
        private static ThreadLocal<Stack<T>> mObjStack = new();

        public static T Create() {
            if (mObjStack == null || mObjStack.Value == null) {
                return new T();
            }
            return mObjStack.Value.Pop();
        }

        public static void Release(T obj) {
            if (mObjStack == null || mObjStack.Value == null) {
                mObjStack.Value = new Stack<T>();
            }
            mObjStack.Value.Push(obj);
        }
    }
}